/*
 * 
 * 
 * @author: Oren Zamir
 */
package org.valire.usermanagement.services;

import java.util.List;

import org.valire.usermanagement.beans.MethodAccessControl;
import org.valire.usermanagement.beans.Role;
import org.valire.usermanagement.beans.User;
import org.valire.util.persistency.GenericJpaDaoImpl;


/**
 * The Class UserDao.
 */
@SuppressWarnings("unchecked")
public class RoleDao extends GenericJpaDaoImpl<Role, Integer> {

	/**
	 * Instantiates a new user dao.
	 */
	public RoleDao() {
		super(Role.class);
	}

	/**
	 * Gets the all available roles.
	 * 
	 * @return the all available roles
	 */
	public List<Role> getAllAvailableRoles() {
		List<Role> results = getJpaTemplate()
				.find("select role from org.valire.usermanagement.beans.Role as role ");
		if (results.size() == 0) {
			return null;
		}
		return results;
	}

	/**
	 * Gets the all roles for method.
	 * 
	 * @param method
	 *            the method
	 * @return the all roles for method
	 */
	public List<Role> getAllRolesForMethod(String method) {
		List<MethodAccessControl> results = getJpaTemplate()
				.find("select acm from org.valire.usermanagement.beans.AccessControlMethod as acm ");
		if (results.size() == 0) {
			return null;
		}
		//return results;
		return null;
	}

	/**
	 * Can user access method.
	 * 
	 * @param user
	 *            the user
	 * @param method
	 *            the method
	 * @return true, if successful
	 */
	public boolean canUserAccessMethod(User user, String method) {
		return false;
	}

	/**
	 * Gets the role entity bean.
	 *
	 * @param getRole the role name
	 * @return the user bean
	 */
	public User getRole(Integer roleId) {
		List<User> results = getJpaTemplate()
				.find(	"select user from org.valire.usermanagement.beans.Role user where role.id = ?1",	roleId);
		if(results.size() == 0){
			return null;
		}
		return results.get(0);
	}
}
